import { defineStore } from "pinia";
import { getDeptList } from "@/services/mock";

//部门列表
export const useDeptStore = defineStore({
    id: "dept",
    state: () => ({
        deptList: [],
    }),
    //开启数据缓存
    persist: {
        enabled: true,
    },
    getters: {
        DeptList() {
            return this.deptList;
        },
    },
    actions: {
        //获取部门列表
        async getDeptListData() {
            if (this.deptList.length) return;
            let res = await getDeptList();
            if (res.code === 200) {
                this.deptList = res.data;
            }
        },

        //重置部门列表
        resetDeptListData() {
            this.deptList = [];
        }
    },
});
